package o;

import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.text.TextUtils;
import androidx.core.app.NotificationCompat.d;
import com.huawei.appgallery.foundation.application.pkgmanage.model.update.ApkUpgradeInfo;
import com.huawei.appgallery.updatemanager.impl.service.KeyAppUpdateDownloadService;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant.KeyAndValue;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import o.czk.g;
import o.dat.b;

public class dau {
    public static void ˎ(Context context) {
        try {
            List<ApkUpgradeInfo> ˎ = ((czu) dbn.ˎ(czu.class)).ˎ(true, 1);
            if (ˎ.size() <= 0) {
                czi.ˎ.ˊ("NotificationUtils", "show update notification error,updatableApk size is 0");
                cei.ˋ(context, "UpdateManager", 1020);
                return;
            }
            List arrayList = new ArrayList(6);
            StringBuilder stringBuilder = new StringBuilder("");
            d dVar = new d(ContentManager.getInstant().getContext());
            String string = ContentManager.getInstant().getContext().getString(g.ˋˊ, new Object[]{""});
            long j = 0;
            int i = 0;
            for (ApkUpgradeInfo apkUpgradeInfo : ˎ) {
                stringBuilder.append(ContentManager.getInstant().getContext().getString(g.ˋˊ, new Object[]{apkUpgradeInfo.ˊ()}));
                if (i < 6) {
                    try {
                        Bitmap ॱ = ॱ(apkUpgradeInfo);
                        if (ॱ != null) {
                            arrayList.add(ॱ);
                            i++;
                        }
                    } catch (Exception e) {
                        czi.ˎ.ˊ("NotificationUtils", "get icon error!!!!!!" + e.toString());
                    } catch (NoSuchMethodError e2) {
                        czi.ˎ.ˊ("NotificationUtils", "get icon NoSuchMethodError!!!!!!" + e2.toString());
                    }
                }
                j = ˋ(j, apkUpgradeInfo);
            }
            String stringBuilder2 = stringBuilder.toString();
            if (!TextUtils.isEmpty(stringBuilder2)) {
                stringBuilder2 = stringBuilder2.substring(0, stringBuilder2.length() - string.length());
            }
            czi.ˎ.ˋ("NotificationUtils", "show update notify and size " + ˎ.size());
            ॱ(ˎ.size(), j, arrayList, stringBuilder2, dVar);
        } catch (Exception e3) {
            czi.ˎ.ˊ("NotificationUtils", "show UpdateNotification failed, " + e3.toString());
        }
    }

    private static Bitmap ॱ(ApkUpgradeInfo apkUpgradeInfo) {
        Bitmap ˎ = erm.ˏ().ˎ(apkUpgradeInfo.ᐝ(), false);
        if (ˎ == null) {
            return eqx.ˋ(ContentManager.getInstant().getContext(), apkUpgradeInfo.ॱᐝ());
        }
        return ˎ;
    }

    private static void ॱ(int i, long j, List<Bitmap> list, String str, d dVar) {
        dVar.ˊ(str);
        Bundle bundle = new Bundle();
        bundle.putInt("update_notify_app_size", i);
        dVar.ˎ(bundle);
        dVar.ˏ(ContentManager.getInstant().getContext().getResources().getQuantityString(czk$h.ˏ, i, new Object[]{Integer.valueOf(i), epw.ˊ(j)}));
        ˋ(dVar, (List) list);
    }

    private static long ˋ(long j, ApkUpgradeInfo apkUpgradeInfo) {
        if (1 == apkUpgradeInfo.ˊˊ()) {
            return j;
        }
        if (apkUpgradeInfo.ʼ() > 0) {
            return j + apkUpgradeInfo.ʼ();
        }
        return j + apkUpgradeInfo.ʻॱ();
    }

    private static void ˋ(d dVar, List<Bitmap> list) {
        dVar.ˊ(czk$d.ˊ);
        dVar.ˏ(true);
        if (dao.ˏ().ˎ() != null) {
            dVar.ˎ(dao.ˏ().ˎ().ˎ());
        }
        if (VERSION.SDK_INT <= 23) {
            b.ˊ(dVar, list, "");
        } else {
            ˎ(dVar);
        }
        dVar.ˋ(true);
        Notification ˊ = dVar.ˊ();
        Context ˋ = ContentManager.getInstant().getContext();
        cei.ˏ(ˋ, "UpdateManager", 1020, ˊ);
        ((czp) dbn.ˎ(czp.class)).ˊ(ˋ, System.currentTimeMillis());
        String ˏ = ˏ();
        ((czp) dbn.ˎ(czp.class)).ˊ(ˏ, ((czp) dbn.ˎ(czp.class)).ˋ(ˏ) + 1);
        dgh.onEvent(new dge.d(ˋ, g.ᐝ).ˏ(KeyAndValue.NUMBER_01).ˋ());
    }

    private static void ˎ(d dVar) {
        Intent intent = new Intent(ContentManager.getInstant().getContext(), KeyAppUpdateDownloadService.class);
        intent.putExtra(KeyAppUpdateDownloadService.DOWNLOAD_COMMAND, 2);
        dVar.ॱ(czk$d.ˏ, ContentManager.getInstant().getContext().getString(g.ˉ), PendingIntent.getService(ContentManager.getInstant().getContext(), 2016062802, intent, 268435456));
    }

    private static String ˏ() {
        return new SimpleDateFormat("yyyy/MM/dd", Locale.US).format(new Date(System.currentTimeMillis()));
    }
}
